import {
  CanvasTexture,
  CubeTextureLoader,
  MeshStandardMaterial,
  TextureLoader,
} from 'three'
// import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader'
import { TcanvasTextureEditor } from './TcanvasTextureEditor'

const textureLoader = new TextureLoader() //贴图加载器
// const rgbeLoader = new RGBELoader() //加载hdr环境图
const cubeTextureLoader = new CubeTextureLoader()

export const pictureTexture = textureLoader.load('/1.jpg')

export const frameColorTexture = textureLoader.load(
  '/rough_block_wall_diff_2k.jpg'
)
export const frameRoughTexture = textureLoader.load(
  '/rough_block_wall_rough_2k.jpg'
)
export const frameDispTexture = textureLoader.load(
  '/rough_block_wall_disp_2k.jpg'
)

export const frameNormalTexture = textureLoader.load(
  '/rough_block_wall_nor_2k.jpg'
)
export const tipsTexture = new CanvasTexture(
  new TcanvasTextureEditor(1920, 1080).draw((ctx) => {
    ctx.fillStyle = 'white'
    ctx.fillRect(0, 0, 1920, 1080)
    ctx.fillStyle = 'black'
    ctx.textAlign = 'center'
    ctx.textBaseline = 'middle'
    ctx.font = '72px 微软雅黑'
    ctx.translate(960, 440)
    ctx.scale(2, 2)
    ctx.beginPath()
    ctx.fillText('作者,1111', 0, 0)
    ctx.closePath()

    ctx.beginPath()
    ctx.fillText('ID,1111', 0, 80)
    ctx.closePath()

    ctx.beginPath()
    ctx.fillText('时间,1111', 0, 160)
    ctx.closePath()
  }).canvas
)

const aerialRocksColorTexture = textureLoader.load(
  '/aerial_rocks_02_diff_2k.jpg'
)
const aerialRocksRoughTexture = textureLoader.load(
  '/aerial_rocks_02_rough_2k.jpg'
)
const aerialRocksDispTexture = textureLoader.load(
  '/aerial_rocks_02_disp_2k.jpg'
)
// const aeriaRocksAOTexture = textureLoader.load('aerial_rocks_02_ao_2k.jpg')

const aeriaRocksNormalTexture = textureLoader.load(
  '/aerial_rocks_02_nor_2k.jpg'
)

export const aerialTexture = new MeshStandardMaterial({
  map: aerialRocksColorTexture,
  roughnessMap: aerialRocksRoughTexture,
  bumpMap: aerialRocksDispTexture,
  // aoMap: aeriaRocksAOTexture,
  normalMap: aeriaRocksNormalTexture,
})


// 环境cube纹理加载
export const envMapTexture = cubeTextureLoader.load([
  '/右.jpg',
  '/左.jpg',
  '/上.jpg',
  '/下.jpg',
  '/前.jpg',
  '/后.jpg',
])
